extern "C"
{
#include "Downloader_C.h"
}

#include "DownloadManager.hpp"

void * WASM_Ext_GetDownloader(const char * url)
{
    std::shared_ptr<Eyer::Downloader> downloader = Eyer::DownloadManager::GetInstance()->GetDownloader(url);
    std::shared_ptr<Eyer::Downloader> * dPtr = new std::shared_ptr<Eyer::Downloader>(downloader);
    return dPtr;
}

int WASM_Ext_Downloader_Open    (void * downloader)
{
    std::shared_ptr<Eyer::Downloader> * dPtr = (std::shared_ptr<Eyer::Downloader> *)downloader;
    return (*dPtr)->Open();
}

int WASM_Ext_Downloader_Read    (void * downloader, uint8_t *buf, int size, int pos)
{
    std::shared_ptr<Eyer::Downloader> * dPtr = (std::shared_ptr<Eyer::Downloader> *)downloader;
    return (*dPtr)->Read(buf, size, pos);
}

int WASM_Ext_Downloader_Close   (void * downloader)
{
    std::shared_ptr<Eyer::Downloader> * dPtr = (std::shared_ptr<Eyer::Downloader> *)downloader;
    (*dPtr)->Close();
    delete dPtr;
    return 0;
}